/**
 * Carnegie Mellon University
 * School of Computer Science
 * MSIT eBusiness Technology
 * 
 * Team 8 - Infinity (2011 Spring)
 * infinity-team8@googlegroups.com
 * 
 * Professor: Jeffrey L. Eppinger
 * Program Faculty: Sujata Telang
 */

package formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class CustomerSellFundForm extends FormBean {
	private String fundID;
	private String shares;
		
	public String getFundID() { return fundID; }
	public String getShares() { return shares; }
	
	public void setShares(String s) { shares = s.trim(); }
	public void setFundID(String s) { fundID = s.trim(); }
	
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();
		
		if (fundID == null || fundID.length() == 0) {
			errors.add("Fund is required");
		}
		
		if (shares == null || shares.length() == 0) {
			errors.add("Shares is required");
		}
				
		double inputShares = 0;
		
		try {
			inputShares = Double.parseDouble(shares);
		} catch (NumberFormatException e) {
			errors.add("Shares needs to be numeric");
		}
		
		if (errors.size() > 0) {
			return errors;
		}
		
		if (inputShares <= 0) {
			errors.add("Positive shares amount is required");
		}
		
		if (errors.size() > 0) {
			return errors;
		}
		
		if (!shares.matches("[0-9]{0,15}.[0-9]{0,3}")) {
			errors.add("Shares can only have up to three decimal points");
		}
		
		return errors;
	}
}
